package com.zlcx.tz.live.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.zlcx.tz.live.domain.TimeLearnRoomSeatsDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * @author anjl
 * 计时学习自习室座位信息
 */
@ApiModel(value = "计时自习室座位信息")
@Data
@Builder
public class TimeLearnRoomSeatsVO implements Serializable {

    private static final long serialVersionUID = 7070732529671056133L;
    @ApiModelProperty(value = "id")
    private Long id;

    @ApiModelProperty(value = "房间id")
    private Long roomId;

    @ApiModelProperty(value = "用户id")
    private Long userId;

    @ApiModelProperty(value = "用户昵称")
    private String name;

    @ApiModelProperty(position = 60, value = "性别 0 男 1 女")
    private Integer sex;

    @ApiModelProperty(position = 100, value = "用户头像")
    private String avatarUrl;

    @ApiModelProperty(position = 110, value = "是否是自己 1是 0不是")
    private Integer self;

    @ApiModelProperty(position = 171, value = "个人主页使用：是否为道友 0不是 1是")
    private Integer isFriend;

    @ApiModelProperty(position = 171, value = "个人主页使用：是否为该用户的粉丝 0不是 1是")
    private Integer isFans;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(value = "入座时间")
    private Date seatingTime;

    @ApiModelProperty(value = "学习内容")
    private String studyContent;

    @ApiModelProperty(value = "计时分钟数")
    private Integer minutes;

    @ApiModelProperty(value = "座位号")
    private Integer num;

    @ApiModelProperty(value = "专注期间是否使用其他app")
    private Integer useOtherApps;

    @ApiModelProperty(value = "房间时长，单位秒")
    private Long roomTimes;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    public static TimeLearnRoomSeatsVO from(TimeLearnRoomSeatsDO seat) {
        return Objects.isNull(seat) ? null :
                TimeLearnRoomSeatsVO
                        .builder()
                        .createTime(seat.getCreateTime())
                        .roomId(seat.getRoomId())
                        .id(seat.getId())
                        .userId(seat.getUserId())
                        .seatingTime(seat.getSeatingTime())
                        .studyContent(seat.getStudyContent())
                        .num(seat.getNum())
                        .minutes(seat.getMinutes())
                        .useOtherApps(seat.getUseOtherApps())
                        .roomTimes((Objects.isNull(seat.getSeatingTime()) ? 0L : new Date().getTime() - seat.getSeatingTime().getTime()) / 1000)
                        .build();
    }

}